﻿using Microsoft.AspNetCore.Mvc;
using WebApp.Models;

namespace WebApp.Controllers;

[ApiController]
[Route("/departments")]
public class DepartmentsControllers:Controller
{
    
    
    public IActionResult Index()
    {
        return Content("<h1>Departments</h1> Welcome to the departments page!", "text/html");
        // return new ContentResult()
        // {
        //     Content = "<h1>Departments</h1> Welcome to the departments page!", 
        //     ContentType = "text/html"
        // };
    }

    [HttpPost("create")]
    public object Create([FromBody] Department department)
    {
        return department;
    }
    
    public IActionResult Details(int? id)
    {
        return Json(new Department { Id = 1, Name = "Jack" });
        //return new JsonResult(new Department { Id = 1, Name = "Jack" });
        //return new Department { Id = 1, Name = "Jack" };
        //return $"Department info:{id}";
    }

    
    [Route("/download_vf")]
    public IActionResult ReturnVirtualFile()
    {
        return new VirtualFileResult("/readme.txt","text/plain");

    }
    
    [Route("/download_pf")]
    public IActionResult ReturnPhysicalFile()
    {
        return new PhysicalFileResult(@"c:\temp\sample.pdf","application/pdf");

    }
     
    [Route("/download_cf")]
    public IActionResult ReturnContentFile()
    {
        byte[] bytes = System.IO.File.ReadAllBytes(@"c:\temp\sample.pdf");
        
        return new FileContentResult(bytes,"application/pdf");

    }
    
    
    
}